//
//  AddressBookV2.m
//  OC05_NSArray_NSDictionary_NSSet
//
//  Created by Scott on 16/3/2.
//  Copyright © 2016年 Rain. All rights reserved.
//

#import "AddressBookV2.h"

@implementation AddressBookV2

#pragma mark - init
/** 属性字典初始化并添加26个键值对. */
- (instancetype)init {
    
    self = [super init];
    if (self) {
        
        _mDic = [NSMutableDictionary dictionary];
        
        for (char c = 'A'; c <= 'Z'; c++) {
            
            NSMutableArray *mArr = [NSMutableArray array];
            
            NSString *key = [NSString stringWithFormat:@"%c", c];
            
            [_mDic setObject:mArr forKey:key];
        }
    }
    return self;
}

#pragma mark - function
/** 
 * 根据联系人的分组名, 在_mDic字典中找出对应的数组, 然后将联系人添加到此数组中.
 */
- (void)addContact:(Contact *)contact {
    
    NSString *groupName = contact.groupName;
    
    NSMutableArray *mArr = [self.mDic objectForKey:groupName];
    
    [mArr addObject:contact];
}

@end
